//package com.kenliang.javase.serialize;
//
//import lombok.ToString;
//import org.apache.curator.RetryPolicy;
//import org.apache.curator.framework.CuratorFramework;
//import org.apache.curator.framework.CuratorFrameworkFactory;
//import org.apache.curator.retry.ExponentialBackoffRetry;
//
//import java.io.ByteArrayInputStream;
//import java.io.IOException;
//import java.io.ObjectInputStream;
//import java.io.Serializable;
//
///**
// * @author KenLiang
// * @description:反序列化包名，类名，序列化id必须一样，序列化的成员变量可有可无
// *  static 修饰的字段不参与序列化
// *  transit 修饰的变量不参与序列化
// * @date Created in 9:53 AM 2019/3/14.
// */
//@ToString
//public class User implements Serializable {
//    private static final long serialVersionUID = 8294180014912103005L;
//
////    public String username;
//    public transient String passwd1;
//    //
//    public static String  staticField1 = "bean";
//
//
////    public String getUsername() {
////        return username;
////    }
////
////    public void setUsername(String username) {
////        this.username = username;
////    }
//
////    public String getPasswd() {
////        return passwd;
////    }
////
////    public void setPasswd(String passwd) {
////        this.passwd = passwd;
////    }
//
//}
//class Test{
//    public static void main(String[] args) throws Exception {
//
//        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3);
//
//        CuratorFramework client = CuratorFrameworkFactory.builder()
//                .connectString("localhost:2181")
//                .sessionTimeoutMs(5000)
//                .connectionTimeoutMs(5000)
//                .retryPolicy(retryPolicy)
//                .namespace("serialize")
//                .build();
//        client.start();
//        if(client.checkExists().forPath("/user")!=null){
//            byte[] userBytes =client.getData()
//                    .forPath("/user");
//
//            ByteArrayInputStream bais = null;
//            ObjectInputStream ois = null;
//            try {
//                // 反序列化
//                bais = new ByteArrayInputStream(userBytes);
//                ois = new ObjectInputStream(bais);
//                User user  = (User)(ois.readObject());
//                System.out.println(user);
//                System.out.println(User.staticField1);
//            } catch (Exception e) {
//                e.printStackTrace();
//            } finally {
//                try {
//                    bais.close();
//                    ois.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
//}
